package com.lhnstart.learn.bases.exception;

import com.sun.xml.internal.ws.api.model.ExceptionType;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

/**
 * 整数校验
 *
 * @author lhn
 * @date 2023/07/20 22:00
 * @since 1.0.0
 **/
public class TryCatchException01 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个整数:");
        while (true) {
            try {
                String next = scanner.next();
                int parseInt = Integer.parseInt(next);
                break;
            } catch (NumberFormatException e) {
                System.out.print("你输入的不是一个整数, 请重新输入:");
            }
        }

        try (FileInputStream fileInputStream = new FileInputStream("123");) {
             // 使用资源的代码
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            // 进行资源的额外处理。
        }
    }

}